package com.dragon.www.haier.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.dragon.www.haier.R;
import com.dragon.www.haier.util.TimeUtil;
import com.dragon.www.haier.view.TitleView;

/**
 * Created by liqp on 2016/10/27.
 */
public class LefficeActivity extends Activity{

    private ImageView img_smart;
    private ImageView img_office;
    private ImageView img_store;
    private TitleView titleView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.leffice);
        initView();
        readtime();
        titleView.setBackCancel();
        titleView.setTextSetAction(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        img_smart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LefficeActivity.this, com.dragon.www.haier.activity.SmartControlActivity.class);
                startActivity(intent);
            }
        });
        img_office.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        img_store.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }
    public void initView() {
        img_smart = (ImageView) findViewById(R.id.img_smart);
        img_office = (ImageView) findViewById(R.id.img_office);
        img_store = (ImageView) findViewById(R.id.img_store);
        titleView = (TitleView) findViewById(R.id.item_title);
    }
    public void readtime() {
        SharedPreferences sp = getSharedPreferences("INFO", MODE_PRIVATE);
        String createTime  =sp.getString("time", "");
        long time = System.currentTimeMillis();
        if (createTime.equals("")){

            SharedPreferences.Editor ed =sp.edit();
            ed.putString("time", String.valueOf(time));
            ed.commit();
        }else{
            String timeinfo = TimeUtil.getDistanceTime(Long.parseLong(createTime), time);
            if (timeinfo.equals("软件过期")){
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("软件过期！");
                builder.setMessage("请联系开发人员");
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        System.exit(0);
                    }
                });
                AlertDialog ad = builder.create();
                ad.show();
            }
        }
    }
}
